package com.chat.rabbitmq.producer;

import com.chat.bean.WsMessageDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * websocket关闭连接通知推送生产者
 *
 * @author mhw
 * @version v1.0
 * @date 2019-11-19
 */
@Component
@Slf4j
public class WsForcedCloseProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void sendToQueue(String routingKey, String uid, String msgJSON) {
        log.info("路由【{}】给用户【{}】发送消息：【{}】", routingKey, uid, msgJSON);

        WsMessageDTO wsMessageDTO = new WsMessageDTO(uid, msgJSON);
        Message<WsMessageDTO> message = MessageBuilder
                .withPayload(wsMessageDTO)
                .build();

        rocketMQTemplate.syncSend("wsForcedTopic",message);
    }
}
